package de.mfits.fireflyplayer;

import static de.mfits.fireflyplayer.storage.DbHelper.ARTIST;
import static de.mfits.fireflyplayer.storage.DbHelper.ID;
import static de.mfits.fireflyplayer.storage.DbHelper.SONGS;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class BrowseArtistsActivity extends BrowseActivity {

  private static final String TRACKS = "tracks";

  private static final String TABLE = SONGS;
  private static final String[] COLUMNS = { ARTIST + " as " + ID, ARTIST, "count(*) as " + TRACKS };
  private static final String SELECTION = null;
  private static final String GROUP_BY = ARTIST;
  private static final String HAVING = null;
  private static final String ORDER_BY = ARTIST;

  private static final int LAYOUT = R.layout.list_artists;
  private static final String[] FROM = { ARTIST, TRACKS };
  private static final int[] TO = { R.id.artist, R.id.artistTracks };

  public BrowseArtistsActivity() {
    super(TABLE, COLUMNS, SELECTION, GROUP_BY, HAVING, ORDER_BY, LAYOUT, FROM, TO);
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.browse_title_artists);
  }

  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    cursor.moveToPosition(position);
    String artist = cursor.getString(cursor.getColumnIndex(ARTIST));

    Intent intent = new Intent(this, BrowseArtistSongsActivity.class);
    intent.putExtra(ARTIST, artist);
    startActivity(intent);
  }
}
